#include<bits/stdc++.h>
using namespace std;

class Solution
{
private:
    /* data */
public:
    int maxSubArray(vector<int>& nums){
        int len = nums.size();
        if(len<2){
            return nums[0];
        }
        vector<int> vec(nums.size());
        vec[0]=nums[0];
        for(int i=1;i<nums.size();++i){
            vec[i]=max(vec[i-1]+nums[i],nums[i]);
        }
        int res =INT_MIN;
        for(int i=0;i<vec.size();++i){
            res = max(res,vec[i]);
        }
        return res;
    }
};

int main(int argc, char const *argv[])
{
    // vector<int> nums={-2,1,-3,4,-1,2,1,-5,4};
    vector<int> nums={-2,-1};
    Solution s;
    int res = s.maxSubArray(nums);
    cout<<res<<endl;
    return 0;
}


